import { useIntersectionObserver } from '@vueuse/core'
import { ref } from 'vue'
export const useLazyDataFn = (API) => {
  const result = ref([])
  const target = ref(null)
  const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    if (isIntersecting) {
      API().then(ret => {
        result.value = ret.result
        stop()
      })
    }
  })
  return { target, result }
}
